package test;
class Node {
    public int data;
    public Node next;
    public Node(int data) {
        this.data = data;
    }
}
public class MyQueueLinked {
    private Node front;
    private Node rear;
    private int usedSize;
    public void offer(int val) {
        Node node=new Node(val);
        if (front==null){
            this.front=node;
            this.rear=node;
        }
        else {
            this.rear.next=node;
            this.rear=node;
        }
        this.usedSize++;
    }
    public int size() {
        return this.usedSize;
    }
    public boolean isEmpty() {
        return this.usedSize == 0;
    }
    public int poll() {
        if (isEmpty()) {
            throw new RuntimeException("队列为空！");
        }
        int val=this.front.data;
        if(this.front.next == null) {
            this.front = null;
            this.rear = null;
        }
        else {
            this.front=this.front.next;
        }
        this.usedSize--;
        return val;
    }
    public int peek(){
        if (isEmpty()) {
            throw new RuntimeException("队列为空！");
        }
        return this.front.data;
    }
}
